package com.guoshengdeu.door.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.Picture;
import com.guoshengdeu.door.service.IPictureService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 *  @since 2021-06-01
 */
@Api("图片管理")
@RestController
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private IPictureService pictureService;

    //查询picture
    @ApiOperation("查询")
    @RequestMapping("list")
    public List<Picture> queryPicture(){
        return pictureService.list();
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addpicture")
    public RespResult addPicture(@RequestBody Picture picture){
        boolean saveOrUpdate = pictureService.saveOrUpdate(picture);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除picture
    @ApiOperation("删除")
    @DeleteMapping("delepicture")
    public RespResult delePicture(int id){
        boolean removeById = pictureService.removeById(id);
        if(removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult page(Page<Picture> page){
        Page<Picture> pages = pictureService.page(page);
        return RespResult.success(pages);
    }


}
